package com.msb.thinkood.v3;

import java.util.ArrayList;
import java.util.List;

/**
 * author: xl
 * time: 2018/10/31 9:57
 * description:
 **/
public class Farm {

    List<Cow> list=new ArrayList<>();

    int  cultivation(int year){
        for (int i = 0; i <year ; i++) {
            List<Cow> newList =new ArrayList<>();
            for (int j = 0; j <list.size() ; j++) {
                Cow  cow =  list.get(j);
                if(cow.getAge()>4){
                       System.out.println(cow.getAge()+"岁母牛"+"产下一头小母牛，放入农场");
                       Cow littleCow = cow.giveBirthCow(cow);
                       newList.add(littleCow);
                }
                cow.setAge(cow.getAge()+1);
             }
            list.addAll(newList);
            System.out.println("第"+(i+1)+"年总共产牛"+list.size());
        }
        return list.size();
    }

    void addCow(Cow cow){
        list.add(cow);
    }


    public List<Cow> getList() {
        return list;
    }

    public void setList(List<Cow> list) {
        this.list = list;
    }
}
